//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<CDynamicVertex9.cpp>
///	@path	~/src/graphics/dx9/
///	@date	2009/01/10
///	@desc	.

#include "config/config.h"

#include "graphics/dx9/CDynamicVertex9.h"

namespace xeres {

	IMPL_IOBJECT_CLASS( CDynamicVertex9 );

	// CDynamicVertex9
	CDynamicVertex9::CDynamicVertex9( IDirect3DVertexBuffer9 * buffer , size_t count , size_t stride )
		: CBaseVertex9( buffer , count , stride )
	{
	}
	// ~CDynamicVertex9
	CDynamicVertex9::~CDynamicVertex9( void )
	{
	}
	// Map
	bool CDynamicVertex9::Map( bool discard , ResourceMap& data )
	{
		if( m_pBuffer == NULL )
			return false;

		void * pData = NULL;
		HRESULT hr = m_pBuffer->Lock( 0 , 0 , &pData , 0 );
		if( FAILED(hr) )
		{
			TRACE_ERROR( _S("CDynamicVertex9::Map: Failed to lock vertex buffer: %s") ,
				d3d_get_err(hr) );
			return false;
		}
		data.Map( (byte*)pData , m_desc.Size , m_stride , m_vertexCount );
		return true;
	}
	// ReadBack
	bool CDynamicVertex9::ReadBack( ResourceMap& data , bool readonly )
	{
		TRACE_ERROR( _S("CConstantVertex9::ReadBack: Constant vertex is not lockable for read.") );
		return false;
	}
	// Unmap
	bool CDynamicVertex9::Unmap( void )
	{
		if( m_pBuffer == NULL )
			return false;

		m_pBuffer->Unlock();
		return true;
	}

} // namespace xeres
